"""
A class to exercise the JT core functions.
"""
import itk
import vtk
import JT
import Calibration
from numpy import array

def Test():
    """
    Test the volume rendering implemented in JT
    """
    inputVolFileName = 'C:/Users/bryan/bryan-code/2D3D/vert1/CT/ucharCTv1r1.mha'
    staFile = 'C:/Users/bryan/bryan-code/2D3D/vert1/CT/ucharCTv1r1.sta'
    calFileLat = 'C:/Users/bryan/bryan-code/trunk/Tests/ext_cal1.txt'
    inputFixedFileName = 'C:/Users/bryan/bryan-code/2D3D/vert1/fluoro/ushortim080-LAT.mha'

    #
    # Generate Lateral Projection
    #%###########################
    xraycamLat = JT.XRayCamera()
    drrLat = JT.DRR()
    calLat = Calibration.ExternalCalibration()

    calLat.LoadConsolidatedCalibration(calFileLat)
    calLat.LoadStaFile(staFile)
    drrLat.SetXRayCamera(xraycamLat)
    drrLat.SetVolumeFilename(inputVolFileName)

    #
    # Automatic calibration
    #%##########################
    xraycamLat.SetExternalCalibration(calLat)

    vtkMatrixLAT = calLat.ConvertNumpyToVTKArray(calLat._VolumeT)
    drrLat.SetVolumeUserMatrix(vtkMatrixLAT)
    drrLat.SetBlackOnWhiteImage()

    #
    # Read Background Image
    #%##########################
    reader = vtk.vtkMetaImageReader()
    caster = vtk.vtkImageCast()
    flipper = vtk.vtkImageFlip()
    flipper.SetFilteredAxis(1)


    reader.SetFileName(inputFixedFileName)
    reader.Update()

    flipper.SetInput(reader.GetOutput())

    backgroundImage = reader.GetOutput()

    #
    # Set Background Image
    #%##########################
    drrLat.SetBackgroundImage(backgroundImage)

    drrLat.Render()


if __name__ == "__main__":
    Test()